package app

import (
	"chatgpt/helper/code"
	"chatgpt/logq"
	"chatgpt/plugin/rpcx"
	"chatgpt/services/datasrv/sqlhelper"
	"context"
)

func (self *AppApi) UserSelect(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "UserSelect", req, res)
	if err != nil {
		logq.Error("DataSrv.User.Select err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) UserSave(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "UserSave", req, res)
	if err != nil {
		logq.Error("DataSrv.User.Save err:", err)
		res.MsgCode = code.DATA_CALL_ERROR
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) UserTotal(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "UserTotal", req, res)
	if err != nil {
		logq.Error("DataSrv.User.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) UserFirst(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "UserFirst", req, res)
	if err != nil {
		logq.Error("DataSrv.User.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) UserDelete(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "UserDelete", req, res)
	if err != nil {
		logq.Error("DataSrv.User.Delete err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}
